package netty.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @ClassName MyMessageDecoder
 * @Description TODO
 * @Author director吴
 * @Date 2022/5/17 17:06
 * @Version 1.0
 **/
public class MyMessageDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        System.out.println("解码器被调用");
        int i = byteBuf.readInt();

        byte[] bytes = new byte[i];

        byteBuf.readBytes(bytes);

        MessageProtocol messageProtocol = new MessageProtocol();
        messageProtocol.setLenth(i);
        messageProtocol.setCount(bytes);

        list.add(messageProtocol);

    }
}
